package com.yequan.leetcode.tree.preordertraversal_144;

import com.yequan.leetcode.tree.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * 前序遍历
 *
 * @author : Administrator
 * @date : 2020/3/26
 */
public class ReCodePreorderTraversal {

    /**
     * 递归法
     */
    class Factorial {
        public List<Integer> preorderTraversal1(TreeNode root) {
            List<Integer> res = new ArrayList<>();
            helper(root, res);
            return res;
        }

        private void helper(TreeNode root, List<Integer> res) {

            if (null != root) {
                res.add(root.val);
                if (null != root.left) {
                    helper(root.left, res);
                }
                if (null != root.right) {
                    helper(root.right, res);
                }
            }
        }

    }

}
